package company

import (
	"github.com/gin-gonic/gin"
	"jwgin/model/mysql"
	"jwgin/service"
)

type activitySignRecord struct {
}

func (l *activitySignRecord) Routers(Router *gin.RouterGroup) {
	Router.GET("sign/record", l.get)
}

func (activitySignRecord) get(c *gin.Context) {
	count, size, offset := pages(c)
	db := service.G.Model(mysql.ActivitySignRecord{}).
		Joins("JOIN `activity` ON activity.id = activity_sign_record.activity_id").
		Joins("JOIN `company` ON company.id = activity.comid").
		Joins("JOIN `activity_template` ON activity_template.id = activity.activity_template_id").
		Joins("LEFT JOIN `activity_sign_rule` ON activity_sign_rule.sid = activity.id")
	//时间筛选
	startTime := c.Query("startTime")
	endTime := c.Query("endTime")
	if startTime != "" && endTime != "" {
		db = db.Where(" user.addtime > ? AND user.addtime < ? ", startTime, endTime)
	}
	list := []map[string]interface{}{}
	db.Select("").Count(&count).Offset(offset).Limit(size).Order("id DESC").Scan(&list)
	RespList(c, count, list)
}
